package recite.word.redis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.password}")
    private String password;
    
    @Value("${spring.redis.database}")
    private String database;


    @Bean
    public RedissonClient getRedisson(){
        Config config = new Config();
        //单机模式  依次设置redis地址和密码
        System.out.println(host + "  " + port + "  " + password + "  " + database);
        config.useSingleServer().setAddress("redis://" + host + ":" + port)
                .setDatabase(Integer.parseInt(database))
                .setPassword(password);
        return Redisson.create(config);
    }
}
